package com.ruoyi.network.dao;

import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.util.DigestUtils;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.uuid.UUID;
import com.ruoyi.network.domain.NetworkEdge;
import com.ruoyi.network.mapper.NetworkEdgeMapper;

/**
 * 边缘端Dao层
 * 
 * @author ruoyi
 * @date 2024-09-18
 */
@Repository
public class NetworkEdgeDao
{
    @Autowired
    private NetworkEdgeMapper networkEdgeMapper;

    /**
     * 查询边缘端
     * 
     * @param id 边缘端主键
     * @return 边缘端
     */
    public NetworkEdge selectById(String id)
    {
        return networkEdgeMapper.selectById(id);
    }

    /**
     * 查询边缘端列表
     * 
     * @param networkEdge 边缘端
     * @return 边缘端
     * @throws Exception
     */
    public List<Map<String, Object>> queryList(Map<String, Object> param) throws Exception
    {
        List<Map<String, Object>> list = networkEdgeMapper.queryList(param);
        //BeanUtils.caseFormat(list); 在Mybatis拦截器插件中统一处理
		return list;
    }
    
    /**
     * 查询边缘端列表
     * 
     * @param networkEdge 边缘端
     * @return 边缘端
     */
    public List<NetworkEdge> selectList(NetworkEdge networkEdge)
    {
        return networkEdgeMapper.selectList(networkEdge);
    }

    /**
     * 新增边缘端
     * 
     * @param networkEdge 边缘端
     * @return 结果
     */
    public int insert(NetworkEdge networkEdge)
    {
    	if (StringUtils.isBlank(networkEdge.getId())) {
			byte[] bytes = UUID.randomUUID().toString().getBytes();
			networkEdge.setId(DigestUtils.md5DigestAsHex(bytes));
		}
        networkEdge.setCreateTime(DateUtils.getNowDate());
        return networkEdgeMapper.insert(networkEdge);
    }

    /**
     * 修改边缘端
     * 
     * @param networkEdge 边缘端
     * @return 结果
     */
    public int update(NetworkEdge networkEdge)
    {
        networkEdge.setUpdateTime(DateUtils.getNowDate());
        return networkEdgeMapper.update(networkEdge);
    }

    /**
     * 批量删除边缘端
     * 
     * @param ids 需要删除的边缘端主键
     * @return 结果
     */
    public int deleteByIds(String[] ids)
    {
        return networkEdgeMapper.deleteByIds(ids);
    }

    /**
     * 删除边缘端信息
     * 
     * @param id 边缘端主键
     * @return 结果
     */
    public int deleteById(String id)
    {
        return networkEdgeMapper.deleteById(id);
    }

	public int diableOtherEdges(String id) {
		return networkEdgeMapper.diableOtherEdges(id);
	}
}
